﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmNhomHangHoa_thuong

    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTen_Nhom As System.Windows.Forms.TextBox
    Friend WithEvents txtMa_Nhom As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents MatinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TentinhDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents GhichuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MamienDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ManhomhanghoaDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TennhomhanghoaDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn1 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataSetForm_Don As PHUQUI.DataSetForm_Don
    Friend WithEvents DoanhthuDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienvuotDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienthuongDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TientongDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TxtDinhmuc As System.Windows.Forms.TextBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Txttienluong As System.Windows.Forms.TextBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Txttyle As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents TblnhomhanghoathuongBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataGridViewTextBoxColumn2 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DataGridViewTextBoxColumn3 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DinhmucDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TienluongDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TyleDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNhomHangHoa_thuong))
        Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtTen_Nhom = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtMa_Nhom = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.DataGridViewTextBoxColumn2 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DataGridViewTextBoxColumn3 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DinhmucDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TienluongDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TyleDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TblnhomhanghoathuongBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetForm_Don = New PHUQUI.DataSetForm_Don
        Me.TxtDinhmuc = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.Txttienluong = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.Txttyle = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TblnhomhanghoathuongBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetForm_Don, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(289, 114)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 6
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtTen_Nhom
        '
        Me.txtTen_Nhom.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTen_Nhom.Location = New System.Drawing.Point(367, 45)
        Me.txtTen_Nhom.MaxLength = 50
        Me.txtTen_Nhom.Name = "txtTen_Nhom"
        Me.txtTen_Nhom.Size = New System.Drawing.Size(300, 22)
        Me.txtTen_Nhom.TabIndex = 2
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(305, 48)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(59, 16)
        Me.Label3.TabIndex = 14
        Me.Label3.Text = "Tên Nhóm"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtMa_Nhom
        '
        Me.txtMa_Nhom.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMa_Nhom.Location = New System.Drawing.Point(192, 45)
        Me.txtMa_Nhom.MaxLength = 10
        Me.txtMa_Nhom.Name = "txtMa_Nhom"
        Me.txtMa_Nhom.Size = New System.Drawing.Size(113, 22)
        Me.txtMa_Nhom.TabIndex = 1
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(132, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(57, 16)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Mã Nhóm"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(173, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(438, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "ĐỊNH MỨC DOANH THU - LƯƠNG - THƯỞNG"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(179, 114)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 7
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(397, 114)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(88, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(503, 114)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(88, 24)
        Me.BtnClose.TabIndex = 30
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.DataGridViewTextBoxColumn2, Me.DataGridViewTextBoxColumn3, Me.DinhmucDataGridViewTextBoxColumn, Me.TienluongDataGridViewTextBoxColumn, Me.TyleDataGridViewTextBoxColumn})
        Me.DataGridView1.DataSource = Me.TblnhomhanghoathuongBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(42, 165)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.RowHeadersWidth = 25
        Me.DataGridView1.Size = New System.Drawing.Size(720, 396)
        Me.DataGridView1.TabIndex = 40
        '
        'DataGridViewTextBoxColumn2
        '
        Me.DataGridViewTextBoxColumn2.DataPropertyName = "ma_nhom_hanghoa"
        Me.DataGridViewTextBoxColumn2.HeaderText = "Mã nhóm"
        Me.DataGridViewTextBoxColumn2.Name = "DataGridViewTextBoxColumn2"
        Me.DataGridViewTextBoxColumn2.ReadOnly = True
        Me.DataGridViewTextBoxColumn2.Width = 120
        '
        'DataGridViewTextBoxColumn3
        '
        Me.DataGridViewTextBoxColumn3.DataPropertyName = "ten_nhom_hanghoa"
        Me.DataGridViewTextBoxColumn3.HeaderText = "Tên nhóm"
        Me.DataGridViewTextBoxColumn3.Name = "DataGridViewTextBoxColumn3"
        Me.DataGridViewTextBoxColumn3.ReadOnly = True
        Me.DataGridViewTextBoxColumn3.Width = 250
        '
        'DinhmucDataGridViewTextBoxColumn
        '
        Me.DinhmucDataGridViewTextBoxColumn.DataPropertyName = "dinhmuc"
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle2.Format = "N0"
        Me.DinhmucDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle2
        Me.DinhmucDataGridViewTextBoxColumn.HeaderText = "Định mức"
        Me.DinhmucDataGridViewTextBoxColumn.Name = "DinhmucDataGridViewTextBoxColumn"
        Me.DinhmucDataGridViewTextBoxColumn.ReadOnly = True
        '
        'TienluongDataGridViewTextBoxColumn
        '
        Me.TienluongDataGridViewTextBoxColumn.DataPropertyName = "tienluong"
        DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle3.Format = "N0"
        Me.TienluongDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle3
        Me.TienluongDataGridViewTextBoxColumn.HeaderText = "Tiền lương"
        Me.TienluongDataGridViewTextBoxColumn.Name = "TienluongDataGridViewTextBoxColumn"
        Me.TienluongDataGridViewTextBoxColumn.ReadOnly = True
        '
        'TyleDataGridViewTextBoxColumn
        '
        Me.TyleDataGridViewTextBoxColumn.DataPropertyName = "tyle"
        DataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle4.Format = "N0"
        Me.TyleDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle4
        Me.TyleDataGridViewTextBoxColumn.HeaderText = "Tỷ lệ"
        Me.TyleDataGridViewTextBoxColumn.Name = "TyleDataGridViewTextBoxColumn"
        Me.TyleDataGridViewTextBoxColumn.ReadOnly = True
        '
        'TblnhomhanghoathuongBindingSource
        '
        Me.TblnhomhanghoathuongBindingSource.DataMember = "tbl_nhom_hanghoa_thuong"
        Me.TblnhomhanghoathuongBindingSource.DataSource = Me.DataSetForm_Don
        '
        'DataSetForm_Don
        '
        Me.DataSetForm_Don.DataSetName = "DataSetForm_Don"
        Me.DataSetForm_Don.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'TxtDinhmuc
        '
        Me.TxtDinhmuc.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtDinhmuc.Location = New System.Drawing.Point(191, 71)
        Me.TxtDinhmuc.MaxLength = 100
        Me.TxtDinhmuc.Name = "TxtDinhmuc"
        Me.TxtDinhmuc.Size = New System.Drawing.Size(113, 22)
        Me.TxtDinhmuc.TabIndex = 3
        Me.TxtDinhmuc.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(134, 74)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(54, 16)
        Me.Label5.TabIndex = 42
        Me.Label5.Text = "Định mức"
        '
        'Txttienluong
        '
        Me.Txttienluong.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Txttienluong.Location = New System.Drawing.Point(367, 71)
        Me.Txttienluong.MaxLength = 100
        Me.Txttienluong.Name = "Txttienluong"
        Me.Txttienluong.Size = New System.Drawing.Size(138, 22)
        Me.Txttienluong.TabIndex = 4
        Me.Txttienluong.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(307, 74)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(57, 16)
        Me.Label6.TabIndex = 44
        Me.Label6.Text = "Tiền lương"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Txttyle
        '
        Me.Txttyle.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Txttyle.Location = New System.Drawing.Point(580, 71)
        Me.Txttyle.MaxLength = 100
        Me.Txttyle.Name = "Txttyle"
        Me.Txttyle.Size = New System.Drawing.Size(87, 22)
        Me.Txttyle.TabIndex = 5
        Me.Txttyle.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(511, 74)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(63, 16)
        Me.Label9.TabIndex = 46
        Me.Label9.Text = "Tỷ lệ ( % )"
        Me.Label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'frmNhomHangHoa_thuong
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.Txttyle)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.Txttienluong)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.TxtDinhmuc)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtTen_Nhom)
        Me.Controls.Add(Me.txtMa_Nhom)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmNhomHangHoa_thuong"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Dinh muc Doanh Thu - Luong - Thuong "
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TblnhomhanghoathuongBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetForm_Don, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1 As DataTable
    Private da As MySqlDataAdapter
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""
    Sub SetclearData()
        Me.txtMa_Nhom.Text = ""
        Me.txtTen_Nhom.Text = ""
        Me.TxtDinhmuc.Text = ""
        Me.Txttienluong.Text = ""
        Me.Txttyle.Text = ""

    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput(txtMa_Nhom.Text, txtTen_Nhom.Text) Then
            Dim txtMaTinh = Me.txtMa_Nhom.Text.Trim
            sqlQuery = "SELECT ma_nhom_hanghoa FROM tbl_nhom_hanghoa_thuong WHERE ma_nhom_hanghoa = '" & txtMaTinh & "'"
            Dim existedMaTinh As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMaTinh = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_nhom_hanghoa_thuong "
                sqlQuery += "SET "
                sqlQuery += "ma_nhom_hanghoa = '" & txtMaTinh & "'"
                sqlQuery += ", ten_nhom_hanghoa = '" & Me.txtTen_Nhom.Text.Trim & "'"
                sqlQuery += ", dinhmuc = '" & Me.TxtDinhmuc.Text.Trim & "'"
                sqlQuery += ", tienluong = '" & Me.Txttienluong.Text.Trim & "'"
                sqlQuery += ", tyle = '" & Me.Txttyle.Text.Trim & "'"
                sqlQuery += " WHERE ma_nhom_hanghoa= '" & txtMaTinh & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_nhom_hanghoa_thuong"
                    Me.loadDanhSachNhomHangHoa(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If

            Else
                If existedMaTinh = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_nhom_hanghoa_thuong "
                    sqlQuery += "(ma_nhom_hanghoa, ten_nhom_hanghoa,dinhmuc,tienluong,tyle) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & txtMaTinh.ToUpper & "', "
                    sqlQuery += "'" & Me.txtTen_Nhom.Text.Trim & "', "
                    sqlQuery += "'" & Me.TxtDinhmuc.Text.Trim & "',"
                    sqlQuery += "'" & Me.Txttienluong.Text.Trim & "',"
                    sqlQuery += "'" & Me.Txttyle.Text.Trim & "'"
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_nhom_hanghoa_thuong"
                        Me.loadDanhSachNhomHangHoa(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If
        '*******************************************************************
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        txtMa_Nhom.Focus()
    End Sub


    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        Dim txtMaTinh As String = Trim(Me.txtMa_Nhom.Text)

        If txtMaTinh = "" Then
            MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        Else
            Dim txtTenTinh As String = Trim(Me.txtTen_Nhom.Text)
            moduleConstants.MessageWarning = "Bạn có muốn xóa  " & txtMaTinh & "(" & txtTenTinh & ") ?"

            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_nhom_hanghoa_thuong WHERE ma_nhom_hanghoa = '" & txtMaTinh & "'"
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_nhom_hanghoa_thuong"
                    Me.loadDanhSachNhomHangHoa(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        End If
        '*************************************************
    End Sub

    Private Sub frmNhomHangHoa_thuong_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadDanhSachNhomHangHoa("SELECT * FROM tbl_nhom_hanghoa_thuong")

    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub

    'Private Sub BtnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnIn.Click
    '    FrmCrNhomHangHoa.Show()
    'End Sub
    Function checkInput(ByVal ma As String, ByVal ten As String) As Boolean
        Dim result As Boolean = True
        If ma = "" Then
            MessageBox.Show("Bạn chưa chọn Mã  !")
            result = False
        Else
            If ten = "" Then
                MessageBox.Show("Bạn chưa nhập tên !")
                result = False
            End If
        End If
        Return result
    End Function
    Private Sub loadDanhSachNhomHangHoa(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.txtMa_Nhom.Text = Me.DataGridView1.Item(0, iRow).Value
        Me.txtTen_Nhom.Text = Me.DataGridView1.Item(1, iRow).Value
        Me.TxtDinhmuc.Text = Me.DataGridView1.Item(2, iRow).Value
        Me.Txttienluong.Text = Me.DataGridView1.Item(3, iRow).Value
        Me.Txttyle.Text = Me.DataGridView1.Item(4, iRow).Value

    End Sub

 
End Class


